#!/bin/bash

if [[ "$1" == "kill" ]]; then
    pkill tun
    exit
fi

pkill tun
setcap cap_net_admin=eip ./tun
./tun  &
pid=$!
echo $pid

sleep 2

ip link set dev tun0 address 8c:16:45:be:e6:dd
ip addr add 192.168.2.100/24 dev tun0
ip link set dev tun0 up

ifconfig tun0

trap "kill $pid" INT TERM 
wait $pid
